<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>职位管理</title>
<link href="<c:url value='/insdep/reset.min.css' />" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/easyui_full.css'/>" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/icon.css'/>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<c:url value='/insdep/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/jquery.easyui-1.5.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/insdep-extend.min.js'/>"></script>

<link href="<c:url value='/css/wsf-button.css'/>" rel="stylesheet" type="text/css">
</head>
<body> 
	<script type="text/javascript">
		$(function(){
			 //重置
			$("#reset").linkbutton({
				onClick:function(){
					$("#position_search_from").form('reset');
					$("#position_info_dg").datagrid('load');
				}
			});
			var localdeptid;
			//树的选中事件
			$('#dept_info_tree').tree({
				onSelect: function(node){
					localdeptid = node.id;
					$("#hidden_dept_id").val(node.id);
					$('#position_info_dg').datagrid({
							url:'find_AllPosition',
							queryParams: {
							deptid: node.id
							}
					});
				}
			});
			
			//树的默认选中项,并加载数据
			$("#dept_info_tree").tree({
				onLoadSuccess : function(){
					//获取根节点
					var root = $('#dept_info_tree').tree('getRoot'); 
					//默认选中根节点
					var node = $('#dept_info_tree').tree('find', root.id);
					$('#dept_info_tree').tree('select', node.target);
				}
			}); 
			//刷新
			$("#positioninfo_refresh").linkbutton({
				onClick:function(){
					$("#position_info_dg").datagrid('load');
				}
			});
			//根据职位名称查询职位
			$("#searcher").linkbutton({
					onClick:function(){
						$("#position_search_from").form({
							onSubmit:function(param){
								param.deptid=localdeptid;
								param.page='1';
								param.rows='2';
								
							},
							success:function(data){
								var result = $.parseJSON(data);
								$("#position_info_dg").datagrid('loadData', result);
							}
						}).submit();
					}
			}); 
			//分页把参数带过去
			$("#position_info_dg").datagrid({
				onBeforeLoad:function(param){
					param.posname = $("#positionsearchname").val();
				}
			});
			//新增职位
			$("#create_new_postition").linkbutton({
				onClick:function(){
					$("#position_info_win").window({
					      width: 400,
				          height: 470,
				          title: '新建职位窗口',
				          iconCls: 'icon-update',
				          modal: true,//表示模式窗口
				          maximizable:false,
				          minimizable:false,
				          collapsible:false,
				          draggable: false ,
				          deptid: localdeptid,
						  href:'to_CreatePosition',//请求远程数据
						  onLoad : function() {
							//初始化表单
							$('#create_position').form('load',{
								positionId:0,
								positionName:'',
								positionLevel:'5',
								positionDesc:'',
								positionOrgan:'',
								superPosition:''
						    	});
							} 
						});
				}
			});
		});
		//编辑职位信息
		function edit_position(index){
			$("#position_info_dg").datagrid('selectRow', index);
			var row = $("#position_info_dg").datagrid('getSelected');
			var deptid = $("#hidden_dept_id").val();
			$("#position_info_win").window({
			      width: 400,
		          height: 470,
		          title: '编辑职位窗口',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable:false,
		          minimizable:false,
		          collapsible:false,
		          draggable: true ,
		          resizable: false,
		          deptid:deptid,
		          poslevel:row.positionLevel,
				  href:'to_CreatePosition',//请求远程数据
				  onLoad : function() {
					  //初始化表单
					  $('#create_position').form('load',{
						  positionId:row.positionId,
						  positionName:row.positionName,
						  positionLevel:row.positionLevel,
						  positionDesc:row.positionDesc,
						  positionOrgan:row.positionOrgan,
						  superPosition:row.superPosition
			    		});
					} 
				});
		}
		//删除职位
		function remove_position(index){
			$("#position_info_dg").datagrid('selectRow', index);
			var row = $("#position_info_dg").datagrid('getSelected');
			$("<form method='post'>").form({
				url:'remove_DeptPosition',
				onSubmit:function(param){
					param.position=row.positionId;
				},
				success:function(info){
					$('#position_info_dg').datagrid('reload');
					alert(info);
				}
			}).submit();
		}
		//在职位下添加员工
		function add_emp_to_position(index){
			$("#position_info_dg").datagrid("selectRow", index);
			var row = $("#position_info_dg").datagrid("getSelected");
			var deptid = $("#hidden_dept_id").val();
			$("#position_add_emp_win").window({
			      width: 300,
		          height: 470,
		          title: '添加员工窗口',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable: false,
		          minimizable: false,
		          collapsible: false,
		          draggable: true ,
		          resizable: false,
		          deptid: deptid,
		          posid: row.positionId,
				  href:'to_PositionAddEmp'//请求远程数据
			});
		}
		//职位详情
		function position_desc_function(index){
			$("#position_info_dg").datagrid('selectRow', index);
			var row = $("#position_info_dg").datagrid('getSelected');
			$("#position_desc_win").window({
			      width: 500,
		          height: 600,
		          title: '职位详情窗口',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable: false,
		          minimizable: false,
		          collapsible: false,
		          draggable: true ,
		          resizable: false,
		          posid: row.positionId,
				  href:'to_PositionDescInfo'//请求远程数据
			});
		}
		//职位操作
		function position_action(val,row,index){
			var position_remove = "", position_add = "", add_emp = "", position_desc = "";
			position_remove = "<a class='button-teal iconfont icon-delete' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='remove_position("+index+")'>删除</a>";
			position_add = "<a class='button-blue iconfont icon-shenqingshenpi' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='edit_position("+index+")'>编辑</a>";
			add_emp = "<a class='button-blue iconfont icon-friendadd' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='add_emp_to_position("+index+")'>分配员工</a>";
			position_desc = "<a class='button-darkblue iconfont icon-friendadd' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='position_desc_function("+index+")'>职位详情</a>"
			return position_remove+position_add+add_emp+position_desc; 
		} 
	</script>
	<div class="easyui-layout" data-options="fit:true">
	<!-- 部门树 -->
	<div data-options="region:'west',title:'部门',split:true" style="width:150px;">
	    <ul id="dept_info_tree" class="easyui-tree" data-options="url:'find_AllDept'"></ul>  
	</div>   
	<!-- 创建一个隐藏域来保存部门ID -->
	<div>
	<input id="hidden_dept_id" type="hidden">
	</div>
	<!-- 查询表单  --> 
    <div data-options="region:'north',title:'职位管理',split:true,collapsed:true" style="padding:10px;height:100px;">
    	<form action="find_AllPosition" id="position_search_from" class="searcher-form" method="post">
			<input name="posname" id="positionsearchname" class="easyui-textbox field" label="部门名称："  labelWidth="70" style="width:300px">
    		<a id="searcher" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-search'">检索</a>
			<a id="reset" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-reload'">重置</a>
    	</form>
    </div>    
    <!-- 数据表格  --> 
    <div data-options="region:'center',border:false" style="border-top: 1px solid #D3D3D3">
		<table id="position_info_dg" class="easyui-datagrid" 
		data-options="
		fit:true,
		fitColumns:true,
		rownumbers: true,
		toolbar: '#position_tb',
		nowrap:false, 
		autoRowHeight:true,
		autoRowWidth:300,
		singleSelect:true,
		pagination:true,
		pageSize: 2,
		pageList:[2,4,6,8]">
		<thead>
			<tr>
				<th data-options="field:'superPositionId', align:'center',hidden:true">上级职位编号</th>
				<th style="width:10%;" data-options="field:'positionId', align:'center',sortable:true">职位编号</th>
				<th style="width:10%;" data-options="field:'positionName', align:'center'">职位名称</th>
				<th style="width:10%;" data-options="field:'positionLevel', align:'center'">职位等级</th>
				<th style="width:10%;" data-options="field:'positionDesc', align:'center'">职位详情</th>
				<th style="width:10%;" data-options="field:'positionOrgan', align:'center'">职位编制</th>
				<th style="width:10%;" data-options="field:'positionNumber', align:'center'">在职人数</th>
				<th style="width:10%;" data-options="field:'superPosition', align:'center'">上级职位</th>
				<th style="width:30%;" data-options="field:'teste', align:'center', formatter:position_action">操作</th>
			</tr>
		</thead>
		</table>
    </div>
    </div> 
    
    
    
    <!--easyui-datagrid当中的工具栏  -->
    <div id="position_tb">
    		<a id="create_new_postition" class="easyui-linkbutton" data-options="iconCls:'icon-add'">创建</a>
    		<a id="positioninfo_refresh" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</a>
    </div>  
 
	<!--点击工具栏弹出的window -->
	<div id="position_info_win"></div>
	<!--点击工具栏弹出的分配员工window -->
	<div id="position_add_emp_win"></div>
	<!--点击工具栏弹出的职位详情window -->
	<div id="position_desc_win"></div>
</body>
</html>